package com.wind;

import java.util.ArrayList;
import java.util.List;

public class WindConstraints {
	
	public static List<WindConstraintViolation> checkForInsert(WindEntity entity) {
		List<WindConstraintViolation> violations = new ArrayList<WindConstraintViolation>();

		WindType type = entity.getType();
		
		for(WindConstraint typeConstraint : type.constraints()) {
			violations.addAll(typeConstraint.checkForInsert(entity));
		}
		
		for(WindTypeAttribute typeAttribute : type.attributes()) {
			for(WindConstraint typeConstraint : typeAttribute.constraints()) {
				violations.addAll(typeConstraint.checkForInsert(entity, typeAttribute));
			}
		}
 		
		return violations;
	}

	public static List<WindConstraintViolation> checkForUpdate(WindEntity entity) {
		List<WindConstraintViolation> violations = new ArrayList<WindConstraintViolation>();

		WindType type = entity.getType();
		
		for(WindConstraint typeConstraint : type.constraints()) {
			violations.addAll(typeConstraint.checkForUpdate(entity));
		}
		
		for(WindTypeAttribute typeAttribute : type.attributes()) {
			for(WindConstraint typeConstraint : typeAttribute.constraints()) {
				violations.addAll(typeConstraint.checkForUpdate(entity, typeAttribute));
			}
		}
 		
		return violations;
	}

	public static List<WindConstraintViolation> checkForDelete(WindEntity entity) {
		List<WindConstraintViolation> violations = new ArrayList<WindConstraintViolation>();

		WindType type = entity.getType();
		
		for(WindConstraint typeConstraint : type.constraints()) {
			violations.addAll(typeConstraint.checkForDelete(entity));
		}
		
		for(WindTypeAttribute typeAttribute : type.attributes()) {
			for(WindConstraint typeConstraint : typeAttribute.constraints()) {
				violations.addAll(typeConstraint.checkForDelete(entity, typeAttribute));
			}
		}
 		
		return violations;
	}
}
